﻿/*
 * Copyright 2008 Pimm Hogeling
 * 
 * This file is part of Bomberleague. Contributions to this file were made
 * by (feel free to add your name and/or e-mail to this list if you believe
 * you should be mentioned here):
 * Pimm Hogeling <pimmhogeling@gmail.com>
 * 
 * Bomberleague is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * Bomberleague is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Bomberleague. If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.bomberleague.input {
	import flash.display.Stage;
	import flash.events.KeyboardEvent;
	public class KeyboardDevice {
		public static function initialize(stage:Stage):void {
			stage.addEventListener(KeyboardEvent.KEY_DOWN, down);
			stage.addEventListener(KeyboardEvent.KEY_UP, up);
		}
		public static function destroy(stage:Stage):void {
			stage.removeEventListener(KeyboardEvent.KEY_DOWN, down);
			stage.removeEventListener(KeyboardEvent.KEY_UP, up);
		}
		private static function down(e:KeyboardEvent):void {
			if (e.keyLocation === 2) { // "Right" control and shift keys.
				InputController.setInputState(e.keyCode ^ 0xC0, true);
			} else {
				InputController.setInputState(e.keyCode, true);
			}
		}
		private static function up(e:KeyboardEvent):void {
			if (e.keyLocation === 2) { // "Right" control and shift keys.
				InputController.setInputState(e.keyCode ^ 0xC0, false);
			} else {
				InputController.setInputState(e.keyCode, false);
			}
		}
	}
}